/*全局共公组件及方法*/
import wrap from '@/components/wrapper.vue'; //外包装
import charts from '@/components/charts.vue'; //图表
import mergeTable from '@/components/mergeTable.vue'; //表格
import Paging from '@/components/Paging.vue'; //分页
import diaPaging from '@/components/diaPaging.vue'; //弹窗分页
import Time from '@/components/Time.vue'; //时间选择
import selectName from '@/components/selectName.vue'; //下拉选择
import iconSvg from '@/components/iconSvg.vue';//小切换导航
import scroll from '@/components/scroll.vue';//滚动视图
import seleBtn from '@/components/seleBtn.vue';//tab切换
import comTitle from '@/components/comTitle.vue';//公共title
import firmList from '@/components/firmList.vue';//实验室右边搜索
import tableDialog from '@/components/tableDialog.vue';//公共表格弹窗
import formDialog from '@/components/formDialog.vue';//公共表单弹窗
import laboratoryRightHeader from '@/components/laboratoryRightHeader.vue';//实验室左边头部
const subArr = [diaPaging,formDialog,tableDialog,laboratoryRightHeader, firmList, comTitle, scroll, seleBtn, iconSvg, wrap, charts,mergeTable, Paging, Time, selectName]

export default {
  install(Vue) {
    subArr.forEach(item => Vue.component(item.name, item))
    /*时间格式处理---参数1：时间、参数2：是否要时分秒 */
    Vue.prototype.$getTime = function (times, status = true, type = "day") {
      const time = new Date(times)
      const year = time.getFullYear();
      const month = (time.getMonth() + 1).toString().padStart(2, '0');
      const day = time.getDate().toString().padStart(2, '0');
      const hours = time.getHours().toString().padStart(2, '0');
      const minute = time.getMinutes().toString().padStart(2, '0');
      const second = time.getSeconds().toString().padStart(2, '0');
      if (status) return `${year}-${month}-${day} ${hours}:${minute}:${second}`;
      switch (type) {
        case 'day':
          return `${year}-${month}-${day}`;
        case 'month':
          return `${year}-${month}`;
        case 'year':
          return `${year}`;
        default:
          return `${year}-${month}-${day}`;
      }
    };
    Vue.prototype.$tips = function (name) {
      this.$notify({
        title: "成功",
        message: `${name}！`,
        type: "success",
        customClass: "tongzhi",
      });
    },
      Vue.prototype.$random = function (num) {
        return Math.floor(Math.random() * +num)
      },
      Vue.directive("ellipsis", {
        inserted(el, binding) {
          el.style.width = `${binding.arg || 100}px`
          el.style.whiteSpace = 'nowrap'
          el.style.overflow = 'hidden';
          el.style.textOverflow = 'ellipsis';
        }
      })
  }
}